<template>
  <el-container class="main">
    <el-header height="48px" id="header">
      <div class="header-aside border-right text-center">
        <el-image class="header-img" :src="teamInfo.other?.saasTeamLogo ? teamInfo.other?.saasTeamLogo : ''"
          fit="contain" :style="isCollapse ? 'width:64px; height: 48px' : 'width: 200px; height: 48px'">
          <template #error>
            <div class="image-slot">
              <span v-text="teamInfo.name || '学习平台教师端'"></span>
            </div>
          </template>
        </el-image>
      </div>
      <div class="el-main">
        <el-breadcrumb>
          <el-breadcrumb-item v-for="(v, i) in route.matched" :key="i" :to="{ name: v.name }">
            {{ v.name }}
          </el-breadcrumb-item>
        </el-breadcrumb>
        <div class="avater-h nav-item-title">
          <el-button size="default" plain class="margin-right20" @click="goStu">跳转到学生网页</el-button>
          <el-avatar style="transform: translateY(7px)" size="small" :src="circleUrl"></el-avatar>
          <span class="avater-name hov" v-text="user ? user.name : ''"></span>
        </div>
      </div>
    </el-header>
    <el-container class="context">
      <NavMenu v-bind="{ isCollapse, setisCollapse }"></NavMenu>
      <el-main class="shadow-zdy">
        <div>
          <router-view v-if="show" class="main-main"></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup lang="ts">
import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus';
import { computed, onMounted, provide, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useStore } from "vuex";
import Studycodemodel from '../../../../mysql_interface/studycodemodel';
import { asyncgetteam, } from "../../api/index";
import { Irunactivityoption, Storekey } from "../../interface";
import NavMenu from "./NavMenu.vue";
const isCollapse = ref(false)
const show = ref(false)
function setisCollapse(v: boolean) {
  isCollapse.value = v
}
const router = useRouter()
const route = useRoute()
const store = useStore(Storekey)
const user = computed(() => {
  // return store.getters.getuser;
  return store.state.user;
});
const teamId = computed(() => {
  return Number(user.value?.teamid)
})

const runactivityoptions = ref<Irunactivityoption[]>([])

provide('runactivityoptions', runactivityoptions)

const teamInfo = ref<Studycodemodel.Iteam>({})
onMounted(async () => {
  //  在线
  await store.dispatch("actionOnlineuser");
  // 
  const onlineRet = await store.dispatch('actiononline')
  if (!onlineRet) {
    router.push({ name: 'Login' })
  }
  show.value = true
  teamInfo.value = await asyncgetteam({ ID: teamId.value });
  store.dispatch('actionteam')
  store.dispatch('actionlabel')
  // 比赛进度
  store.state.socket.on('activityprocess', (e: Irunactivityoption) => {
    const n = runactivityoptions.value.findIndex(t => t.activityid === e.activityid)
    if (n === -1) {
      runactivityoptions.value.push(e)
    } else {
      runactivityoptions.value[n] = e
    }
  })
  // 获取团队信息
})

const circleUrl = computed(() => {
  if (user.value) return user.value.headportrait;
  return "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
})

function goStu() {
  const { origin, pathname } = window.location;
  window.open(`${origin}`)
}
</script>

<style scoped>
.main {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

#header {
  padding: 0;
  display: flex;
  flex-direction: row;
  flex-basis: auto;
  z-index: 3;
}

.avater-name {
  display: inline-block;
  color: rgba(51, 51, 51, 1);
  margin-left: 10px;
}

.context {
  min-height: 100vh;
  padding-bottom: 48px;
}

#header .el-main {
  padding: 0 50px 0 20px;
  box-shadow: 2px 0px 3px 0px #888;
  display: flex;
  align-items: center;
  justify-content: space-between
}

.avater-h {
  line-height: 48px;
}

.nav-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#header .header-aside {
  min-width: 48px;
  height: 48px;
  line-height: 48px;
  overflow: hidden;
  transition: all 0.3s;
}

#header .header-img {
  transition: all 0.3s;
}

.shadow-zdy {
  overflow-y: auto;
  overflow-x: hidden;
  background-color: #fff;
}

.shadow-zdy::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

.shadow-zdy::-webkit-scrollbar-thumb {
  cursor: pointer;
  border-radius: inherit;
  background-color: rgb(167, 173, 179);
  transition: .3s;
  opacity: .5;
}

.shadow-zdy::-webkit-scrollbar-track {
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.1);
}

.el-main {
  padding-top: 20px;
  padding-bottom: 0;
}
</style>
